package cc.yugu.yhdw.webserver.web.controller.security.hdw;

import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.domain.hdw.ExchangePriceTime;
import cc.yugu.yhdw.common.entity.json.ExtResult;
import cc.yugu.yhdw.common.entity.json.PageResult;
import cc.yugu.yhdw.webserver.service.basic.DictItemService;
import cc.yugu.yhdw.webserver.service.hdw.ExchangePriceTimeService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 换电价格
 */
@Controller
@RequestMapping(value = "/security/hdw/exchange_price_time")
public class ExchangePriceTimeController extends SecurityController {

    @Autowired
    ExchangePriceTimeService exchangePriceTimeService;
    @Autowired
    DictItemService dictItemService;

    @RequestMapping(value = "index.htm")
    public void index(Long priceId,int editFlag, Model model) {
        model.addAttribute("priceId", priceId);
        model.addAttribute("editFlag", editFlag);
    }

    @RequestMapping("page.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public PageResult page(ExchangePriceTime search){
        return PageResult.successResult(exchangePriceTimeService.findPage(search));
    }

    @RequestMapping(value = "view.htm", method = RequestMethod.GET)
    public String view(Model model, Long id) {
        ExchangePriceTime entity = exchangePriceTimeService.find(id);
        if(entity == null) {
            return SEGMENT_RECORD_NOT_FOUND;
        }
        model.addAttribute("entity", entity);
        return "/security/hdw/exchange_price_time/view";
    }

    @RequestMapping("add.htm")
    @ViewModel(ViewModel.INNER_PAGE)
    public void add(Long priceId, Model model) {
        model.addAttribute("priceId", priceId);
    }

    @RequestMapping("create.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult create(ExchangePriceTime exchangePriceTime) {
        return exchangePriceTimeService.insert(exchangePriceTime);
    }

    @RequestMapping("edit.htm")
    @ViewModel(ViewModel.INNER_PAGE)
    public String edit(Long id, Model model) {
        ExchangePriceTime exchangePriceTime = exchangePriceTimeService.find(id);
        if(exchangePriceTime == null) {
            return SEGMENT_RECORD_NOT_FOUND;
        }
        model.addAttribute("entity", exchangePriceTime);
        return "/security/hdw/exchange_price_time/edit";
    }

    @RequestMapping("update")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public ExtResult update(ExchangePriceTime entity) {
        return exchangePriceTimeService.update(entity);
    }

    @ResponseBody
    @ViewModel(ViewModel.JSON)
    @RequestMapping(value = "delete.htm")
    public ExtResult delete(Long id) {
        return exchangePriceTimeService.delete(id);
    }

}
